import { mapGetters } from "vuex";
import Qrcode from "vux/src/components/qrcode/index.vue";

import Clipboard from "clipboard";

import template from "./agencyShareTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  data() {
    return {
      jumpUrlxiaxian: "",
      jumpUrlcaijin: "",
      reg_swicth: {},
      size: 80,
      toShare: false,
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  components: {
    Qrcode,
  },
  created() {
    this._getAgencyShare();
  },
  mounted() {},
  methods: {
    copy(e) {
      let vm = this;
      var clipboard = new Clipboard(".tag-read");
      clipboard.on("success", (e) => {
        vm.$vux.toast.show({
          text: "复制成功",
        });

        clipboard.destroy();
      });
      clipboard.on("error", (e) => {
        // 不支持复制
        vm.$vux.toast.show({
          text: "该浏览器不支持自动复制",
        });

        clipboard.destroy();
      });
    },
    _getAgencyShare: function () {
      var params = {
        token: localStorage.getItem("token"),
      };
      this.$vux.loading.show();
      this.$http
        .post(this.urlRequest + "?m=api&c=user&a=agentSharing", params)
        .then((res) => {
          this.$vux.loading.hide();
          if (res.status == 0) {
            this.reg_swicth = res.reg_swicth;
            this.$nextTick(() => {
              this.size =
                document.querySelector(".contentTop p").offsetWidth * 0.85;
            });

            this.jumpUrlxiaxian = this.imgRequest + res.JumpUrl + "&type=2";
            this.jumpUrlcaijin = this.imgRequest + res.JumpUrl + "&type=3";
          }
        });
    },
    _getAgencyShareNew: function () {
      let vm = this;
      var params = {
        token: localStorage.getItem("token"),
      };
      vm.$vux.loading.show();
      vm.$http
        .post(vm.urlRequest + "?m=api&c=app&a=getShortLink", params)
        .then((res) => {
          vm.$vux.loading.hide();
          if (res.status == 0) {
            vm.reg_swicth = res.reg_swicth;
            vm.jumpUrlxiaxian = res.data.app.offline;
            vm.jumpUrlcaijin = res.data.app.money;
          }
        })
        .catch((err) => {
          vm.$vux.loading.hide();
          console.log(err);
        });
    },
  },
  watch: {},
};

// WEBPACK FOOTER //
// ./src/components/personalCenter/agencyShare/agencyShare.vue
